// pages/add/childCpns/date/date.js
const date = new Date()
const month= date.getMonth() + 1
const day = date.getDate()
const years = []
const months = []
const days = []

for (let i = 2017; i <= date.getFullYear(); i++) {
  years.push(i)
}

for (let i = 1; i <= 12; i++) {
  months.push(i)
}

for (let i = 1; i <= 31; i++) {
  days.push(i)
}
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    years: years,
    months: months,
    days: days,
    year: date.getFullYear(),
    month: month,
    day: day,
    value: [9999, month-1, day-1],
  },

  /**
   * 组件的方法列表
   */
  methods: {
    bindChange: function (e) {
      const val = e.detail.value
      console.log('val',val)
      this.setData({
        year: this.data.years[val[0]],
        month: this.data.months[val[1]],
        day: this.data.days[val[2]]
      })
    },
    // 取消事件
    handleCancel(){
      this.triggerEvent('cancel')
    },
    // 确定事件
    handleSure(){
      const year = this.data.year
      const month = this.data.month
      const day = this.data.day
      console.log('date',day)
      this.triggerEvent('sure',{year,month,day})
    }
  }
})
